package com.inforich.web.controller.appManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.appManage.domain.Contact;
import com.inforich.appManage.service.IContactService;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.common.utils.poi.ExcelUtil;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

;

/**
 * 联系人管理Controller
 *
 * @author hjm
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/appManage/contact")
public class ContactController extends BaseController {

  @Autowired
  private IContactService contactService;

  /**
   * 查询联系人管理列表
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:list')")
  @GetMapping("/list")
  public Page<Contact> list(Page<Contact> page, Contact contact) {
    Map<String, Object> map = beanToMap(contact);
    contactService.pageContact(page, map);
    return page;
  }


  /**
   * 导出联系人管理列表
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:export')")
  @Log(title = "联系人管理", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, Contact contact) {
    Map<String, Object> map = beanToMap(contact);
    List<Contact> list = contactService.listContact(map);
    ExcelUtil<Contact> util = new ExcelUtil<Contact>(Contact.class);
    util.exportExcel(response, list, "联系人管理数据");
  }

  /**
   * 获取联系人管理详细信息
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(contactService.getById(id));
  }

  /**
   * 新增联系人管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:add')")
  @Log(title = "联系人管理", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody Contact contact) {
    return toAjax(contactService.save(contact));
  }

  /**
   * 修改联系人管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:edit')")
  @Log(title = "联系人管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody Contact contact) {
    return contactService.updateContact(contact);
  }

  /**
   * 删除联系人管理
   */
  @PreAuthorize("@ss.hasPermi('appManage:contact:remove')")
  @Log(title = "联系人管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(contactService.removeByIds(Arrays.asList(ids)));
  }
}
